//
//  MoneyView.m
//  MyWallet
//
//  Created by 小肥羊 on 15/7/16.
//  Copyright (c) 2015年 小肥羊. All rights reserved.
//

#import "MoneyView.h"

@implementation MoneyView

#pragma mark - 初始化
- (void)awakeFromNib
{
    [[NSBundle mainBundle] loadNibNamed:@"MoneyView" owner:self options:nil];
    self.contentView.frame = self.bounds;
    [self addSubview:self.contentView];
    
    //右划
    UISwipeGestureRecognizer *recognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(drawMoney:)];
    recognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
    [self addGestureRecognizer:recognizerRight];
    //左划
    UISwipeGestureRecognizer *recognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(saveMoney:)];
    recognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [self addGestureRecognizer:recognizerLeft];
    //长按
    UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
    longPressGr.minimumPressDuration = 1.0;
    [self addGestureRecognizer:longPressGr];
}


#pragma mark - 触摸调用方法
/*! @brief 触摸开始时调用此方法 */
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.contentView setBackgroundColor:[UIColor lightGrayColor]];
}
/*! @brief 手离开屏幕，触摸事件结束 */
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.contentView setBackgroundColor:[UIColor whiteColor]];
}
/*! @brief 手在界面上移动 */
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}
/*! @brief 手离开界面 */
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.contentView setBackgroundColor:[UIColor whiteColor]];
}


#pragma mark - 操作
- (void)saveMoney:(UISwipeGestureRecognizer *)tap
{
    if (self.delegate) {
        [self.delegate saveMoney:self];
    }
}

- (void)drawMoney:(UISwipeGestureRecognizer *)tap
{
    if (self.delegate) {
        [self.delegate drawMoney:self];
    }
}

-(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
    if(gesture.state == UIGestureRecognizerStateBegan)
    {
        if (self.delegate) {
            [self.delegate checkCard:self];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
